import { Component, OnInit } from '@angular/core';
import { AxiosService } from '../../axios.service';

@Component({
  selector: 'app-zjfs',
  templateUrl: './zjfs.component.html',
  styleUrls: ['./zjfs.component.scss']
})
export class ZjfsComponent implements OnInit {
  zjfs;
  djqr;
  jcqx;
  dpdw;
  mcqx;
  cxycclsj;
  dbjz;
  listOfData;
  isVisible;
  widthConfig = ['150px', '150px', '150px', '150px', '150px', '200px', '150px', '150px'];
  scrollConfig = { x: '1000px', };
  update = false;

  constructor(public axios: AxiosService) { }

  ngOnInit(): void {
    this.queryData();
  }

  queryData() {
    this.axios.axiosPost('QueryZhuangjiaInfo')
      .then((data) => {
        if (data) {
          console.log(data);
          this.listOfData = data['order'];
          console.log(this.listOfData);
        }
      })
      .catch((err) => {
        console.log(err);
      });
  }

  edit(data) {
    // this.zjfs = data.mode;
    // this.djqr = data.time[0]['value'];
    // this.jcqx = data.time[1]['value'];
    // this.dpdw = data.time[2]['value'];
    // this.mcqx = data.time[3]['value'];
    // this.cxycclsj = data.time[4]['value'];
    // this.dbjz = data.time[5]['value'];
    // this.update = true;
    this.zjfs = data.mode;
    this.dbjz = data.time[0]["value"]
    this.update = true

  }

  clear() {
    this.zjfs = '';
    this.djqr = '';
    this.jcqx = '';
    this.dpdw = '';
    this.mcqx = '';
    this.cxycclsj = '';
    this.dbjz = '';
    this.update = false;
  }

  save() {
    this.axios.axiosPost('AddZhuangjiaInfo', {
      mode: this.zjfs,
      name1: 'dbjz', newValue1: this.dbjz

      // mode: this.zjfs,
      // name1: 'djqr', newValue1: this.djqr,
      // name2: 'jcqx', newValue2: this.jcqx,
      // name3: 'dpdw', newValue3: this.dpdw,
      // name4: 'mcqx', newValue4: this.mcqx,
      // name5: 'cxycclsj', newValue5: this.cxycclsj,
      // name6: 'dbjz', newValue6: this.dbjz
    })
      .then((data) => {
        if (data) {
          console.log(data);
          this.queryData();
        }
      })
      .catch((err) => {
        console.log(err);
      });
  }

  showModal(data) {
    this.isVisible = true;
  }

  handleCancel() {
    this.isVisible = false;
  }

  handleOk() {
    this.axios.axiosPost('DeleteZhuangjiaInfo', { 'mode': this.zjfs })
      .then((data) => {
        console.log(this.zjfs)
        console.log(data)
        if (data['result'] === 'ok') {
          this.isVisible = false;
          this.queryData();
        }
      })
  }

}
